<template>
  <view class="main">
    <NavBar title="修改密码"></NavBar>
    <div class="m1">
      <div class="cell ub ub-ac btc">
        <div class="tit">原密码</div>
        <input class="ub-f1 tx-l" :value="oldPsw" @input="bindInput($event, 'oldPsw')" type="text" placeholder="原密码" />
      </div>
      <div class="cell ub ub-ac btc">
        <div class="tit">新密码</div>
        <input class="ub-f1 tx-l" :value="password" @input="bindInput($event, 'password')" type="password" placeholder="新密码" />
      </div>
      <div class="cell ub ub-ac btc">
        <div class="tit">确认新密码</div>
        <input class="ub-f1 tx-l" :value="againPassword" @input="bindInput($event, 'againPassword')" type="password" placeholder="确认新密码" />
      </div>
    </div>
    <button form-type="submit" type="primary" class="btn" @click="submit">确认修改</button>
  </view>
</template>
<script>
import service from '@/utils/http'
import constant from '@/utils/constant'
import { errDialog, loading } from '@/utils/util'
export default {
    data() {
      return {
        oldPsw: '',
        password: '',
        againPassword: ''
      }
    },
    methods: {
        bindInput(e, param) {
            this[param] = e.detail.value
        },
        submit() {
            if (this.oldPsw == "") {
                return errDialog('请输入原密码')
            }
            if (this.password == "") {
                return errDialog('请输入新密码')
            }
            if (this.againPassword == "") {
                return errDialog('请再次输入新密码')
            }
            if (this.password !== this.againPassword) {
                return errDialog('两次新密码输入不一致')
            }
            const { oldPsw, password, againPassword } = this
            service.post('/app/updatePSW', { oldPsw, password, againPassword }).then(res => {
                uni.showToast({title: '修改密码成功', icon: 'success'})
                setTimeout(() => {
                    uni.navigateBack()
                }, 1200)
            })
        }
    }
}
</script>
<style scoped>
.m1{ background-color: #fff; padding: 0 30rpx;background: #ffffff;}
.cell {height: 96rpx;background: #fff;}
.cell .tit{width: 160rpx; font-size:28rpx;font-weight: bold;}
.cell input {font-size: 28rpx; color: #333; font-size:28rpx}
.subtit{font-size: 28rpx;color: #333;margin-bottom: 20rpx;}
.btn{margin:60rpx auto 30rpx;width: 650rpx;}
</style>